package main

import "github.com/gin-gonic/gin"

type Want struct {
	Title   string   `json:"title,omitempty"`
	Answers []string `json:"answers,omitempty"`
}

var Wants = []Want{}

func done(c *gin.Context, code int, msg string) {
	c.JSON(code, gin.H{
		"code": code,
		"msg":  msg,
	})
}

func main() {
	// gin.SetMode(gin.ReleaseMode)
	router := gin.Default()

	// curl -X POST -H "Content-Type: application/json" -d '{"title":"title","answers":["answer1","answer2"]}' http://localhost:8080/want

	router.POST("/want", func(c *gin.Context) {
		var want Want
		c.Bind(&want)
		Wants = append(Wants, want)
		done(c, 200, "ok")
	})

	// curl -X GET http://localhost:8080/wants
	router.GET("/wants", func(c *gin.Context) {
		c.JSON(200, &Wants)
	})

	router.Run(":8080")

}
